﻿<%@ WebHandler Language="C#" Class="Product_Add" %>

using System;
using System.Web;
using Newtonsoft.Json;
public class Product_Add : IHttpHandler, System.Web.SessionState.IReadOnlySessionState 
{
    OTS.BLL.ProductBLL bll = new OTS.BLL.ProductBLL();
    public void ProcessRequest (HttpContext context) 
    {
        //检验是否登录
        OTS.Common.PageSuccess page = new OTS.Common.PageSuccess();
        if (!OTS.BaseLogin.validataModule(context, (int)OTS.enumSysRight.ProductTypeManager))
        {
            page.success = false;
            page.msg = "非法操作！";

        }
        else
        {
            string _proName = context.Request["product.proName"];
            string _proNO = context.Request["product.proNO"];



            if (null != _proName && !"".Equals(_proName) && null != _proNO && !"".Equals(_proNO))
            {
                OTS.Model.Product model = new OTS.Model.Product();
                model.proName = _proName;
                model.proNO = _proNO;
                model.style = context.Request["product.style"];
                model.material = context.Request["product.mateiral"];
                double _costPrice=0,_wholeSalePrice=0,_retailPrice=0;
                double.TryParse(context.Request["product.costPrice"].ToString(), out _costPrice);
                double.TryParse(context.Request["product.wholeSalePrice"].ToString(), out _wholeSalePrice);
                double.TryParse(context.Request["product.retailPrice"].ToString(), out _retailPrice);
                model.costPrice  = _costPrice;
                model.wholeSalePrice = _wholeSalePrice;
                model.retailPrice = _retailPrice;
                model.especial = context.Request["product.especial"];
                model.unit  = context.Request["product.unit"];
                
                int _id = bll.Add(model);

                page.success = true;
                page.msg = _id.ToString();
            }
            else
            {
                page.success = false;
                page.msg = "参数有误！";

            }
            context.Response.ContentType = "application/x-json";
            context.Response.Charset = "utf-8";
            context.Response.Write(JavaScriptConvert.SerializeObject(page));
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}